package controller;



import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;

import config.model.User;
import service.LoginService;

/**
 * 主页面控制类
 * 
 * @author 陈凌志
 *
 */

//登录主页面无需验证登录的拦截器
@Clear
public class IndexController extends Controller{

	/**
	 * 访问主页面方法
	 * 
	 */
	public void index() {
		render("index.html");
	}
	
	/**
	 * 用户登录方法
	 * 
	 */
	public void login() {
        LoginService loginService = new LoginService();
        User user = getModel(User.class);
        user = loginService.checkUser(user.getUserName(), user.getPwd());
        if(user == null) {//为空表面用户名或者密码错误
        	setAttr("check","no");
        	render("index.html");
        }else {//判断用户权限
        	if(user.getPower().equals("admin")) {
        		setSessionAttr("User", user);
        		setAttr("title","公告信息");
        		redirect("/admin/index?pageNumber=1");
        	}else if(user.getPower().equals("student")) {
        		setSessionAttr("User", user);
        		setAttr("title","公告信息");
        		redirect("/student/index?pageNumber=1");
        	}else {
        		setSessionAttr("User", user);
        		setAttr("title","公告信息");
        		redirect("/teacher/index?pageNumber=1");
        	}
        }
	}
}
